package com.sne.airways.system.controller;

import com.sne.airways.basecore.controller.BaseController;
import com.sne.airways.basecore.exceptions.AppException;
import com.sne.airways.system.dto.TdUserCheckDTO;
import com.sne.airways.system.service.RoleService;
import com.sne.airways.system.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: skyline{http://my.oschina.net/skyline520}
 * Date: 12-11-23
 * Time: 下午5:42
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/system/roleuser")
public class RoleUserController extends BaseController {
    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;
    @RequestMapping("/queryUserCheckedList")
    @ResponseBody
    public void queryUserList(String roleId,String userNo,String userName,String status){
        List<TdUserCheckDTO> userDTOList = userService.queryUserCheckedList(roleId, userNo, userName, status);
        renderJsonArray(userDTOList);
    }
    @RequestMapping("/saveRoleUser")
    @ResponseBody
    public void saveRoleUser(String roleId,String ids,int version){
        if(StringUtils.isBlank(roleId)){
            throw new AppException("角色主键不能为空");
        }
        String[] idArray = new String[ids.length()];
        idArray = ids.split(",");
        roleService.saveRoleUser(roleId,idArray,version);
        renderSuccess();
    }
}
